import { createStore } from "vuex";

export default createStore({
  state() {
    return {
      configInfo: "",
    };
  },
  mutations: {
    SETCONFIGINFO(state, val) {
      state.configInfo = val;
    },
  },
  actions: {
    async GETCONFIGINFO({ commit, state }) {
      if (!state.configInfo) {
        const accountInfo = uni.getAccountInfoSync();
        const appId = accountInfo.miniProgram.appId;
        const collection = uniCloud.database().collection("configInfo");
        const { result } = await collection
          .where({
            appId,
          })
          .get();
        commit("SETCONFIGINFO", result.data[0]);
      }
      return state.configInfo;
    },
  },
  getters: {
    getConfigInfo: (state) => state.configInfo,
  },
});
